package com.xxgc.helloworld.service.Impl;

import com.xxgc.helloworld.bean.Users;
import com.xxgc.helloworld.bean.UsersExample;

import com.xxgc.helloworld.dao.UsersMapper;
import com.xxgc.helloworld.po.Info;
import com.xxgc.helloworld.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
@Service
public class LoginService implements ILoginService {
    //业务逻辑层和dao层关联
    @Autowired
    private UsersMapper um;

    //ctrl + q
    @Override
    public Info namePassLogin(Users u) {
        UsersExample example = new UsersExample();
        example.createCriteria()
                .andUsernameEqualTo(u.getUsername())
                .andPasswordEqualTo(u.getPassword());
        //alt+shift+l    ctrl+alt+v  生成返回结果
        List<Users> users = um.selectByExample(example);
        //判断是否为空
        if (CollectionUtils.isEmpty(users)) {
            return new Info(-200, "用户名或密码错误");
        } else {
            return new Info(200, "登录成功", users.get(0));
        }

    }
}